import java.util.Scanner;

public class Class2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a  = new int[n];
        for (int i=0;i<n;i++){
            a[i] = scanner.nextInt();
        }
       int start = a[0];
        int end = a[n-1];
        if (n==2){
            int ans = start>end?start-end:end-start;
            System.out.println(ans);
            return;
        }
        int min = Integer.MAX_VALUE;
        int[] l_dis = new int[n];
        int[] r_dis = new int[n];
        for (int i=0;i<n;i++){
            l_dis[i] = Math.abs(a[i]-start);
        }
        for (int i=0;i<n;i++){
            r_dis[i] = Math.abs(a[i]-end);
        }
        for (int i=0;i<n;i++){
            min = Math.min(min,Math.abs(l_dis[i]-r_dis[i]));
        }
        System.out.println(min);


    }
}
